﻿using B.MES.Customer.Application.IApplication;
using B.MES.Customer.Domain;
using B.MES.Customer.Domain.DTO;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.MES.Customer.Read.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProduceController : ControllerBase
    {
        private readonly IProduceApplication _produceApplication;
        public ProduceController(IProduceApplication produceApplication)
        {
            _produceApplication = produceApplication;
        }

        /// <summary>
        /// 获取生产信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetProduct()
        {
            var result = _produceApplication.GetProduct();
            return Ok(result);
        }

        /// <summary>
        /// 新增生产
        /// </summary>
        /// <param name="produce">需要添加的生产数据</param>
        /// <returns>受影响行数</returns>
        [HttpPost]
        public IActionResult AddProduce(Produce produce, string? SalesOrderNumber)
        {
            return Ok(_produceApplication.AddProduce(produce,SalesOrderNumber));
        }


        /// <summary>
        /// 生产的显示分页查询
        /// </summary>
        /// <param name="ProCode">生产单号</param>
        /// <param name="pageIndex">当前是第几页</param>
        /// <param name="pageSize">每页需要显示多少条数据</param>
        /// <returns>生产的查询显示分页</returns>
        [HttpGet]
        public IActionResult GetProduceShow(string? ProCode, int pageIndex, int pageSize)
        {
            var list = _produceApplication.GetProduceShow(ProCode, pageIndex, pageSize);
            return Ok(list);
        }

        /// <summary>
        /// 删除生产信息
        /// </summary>
        /// <param name="ProId">ID</param>
        /// <returns>受影响行数</returns>
        [HttpDelete]
        public IActionResult DelteProduce(int ProId)
        {
            var result = Ok(_produceApplication.DelteProduce(ProId));
            return result;
        }

        /// <summary>
        /// 更新生产信息
        /// </summary>
        /// <param name="produce">需要更新的生产信息</param>
        /// <returns>受影响行数</returns>
        [HttpPut]
        public IActionResult UpdateProduce(Produce produce)
        {
            var result = Ok(_produceApplication.UpdateProduce(produce));
            return result;
        }

        /// <summary>
        /// 根据生产Id获取生产信息
        /// </summary>
        /// <param name="ProId">生产Id</param>
        /// <returns>生产信息</returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public IActionResult GetProduceByProId(int ProId)
        {
            var result = Ok(_produceApplication.GetProduceByProId(ProId));
            return result;
        }
    }
}
